package jiali.service.impl;

import jiali.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@Service
@Slf4j
public class UploadServiceImpl implements UploadService {

    @Override
    public void upload(MultipartFile file) {
        try {
            InputStream inputStream = file.getInputStream();
            XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
            XSSFSheet sheet = workbook.getSheetAt(0);
            int lastRowNum = sheet.getLastRowNum();
            for (int i = 1; i <= lastRowNum; i++) {
                Row row = sheet.getRow(i);
                int lastCellNum = row.getLastCellNum();
                if (lastCellNum >= 6) {

                }
                System.out.println(row.getCell(0));
                System.out.println(row.getCell(1));
                // todo ....
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    public void setJson() {

    }

}
